package com.caojing.haolemai.ui.outlets.outletsproductactivity;

import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.caojing.haolemai.bean.outletsproductbean.OutletsProductBean;

import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/10/22 0022.
 */
public class OutletsProductPresenter implements OutletsProductContract.Presenter{
    private OutletsProductContract.View view;
    private OutletsProductContract.Modle modle;

    public OutletsProductPresenter(OutletsProductContract.View view){
        this.view=view;
        this.modle=new OutletsProductModel();
    }

    @Override
    public void getVerticalProductBean(String productId, Map<String, String> params) {
        modle.getProductBean(productId, params, new Callback<OutletsProductBean>() {
            @Override
            public void onResponse(Call<OutletsProductBean> call, Response<OutletsProductBean> response) {
                final OutletsProductBean productBean = response.body();
                Handler handler=new Handler(Looper.getMainLooper());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getProductBeanSucess(productBean);
                    }
                });
            }

            @Override
            public void onFailure(Call<OutletsProductBean> call, Throwable t) {
                Log.i("TAG", t.getMessage());
                view.getProductBeanFail("网络连接失败");

            }
        });

    }
}
